import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex) // vue的插件机制
// Vuex.Store 构造器选项
require('@/common/unifun.js')(uni);
// console.log(uni)
const store = new Vuex.Store({
    // 为了不和页面或组件的data中的造成混淆，state中的变量前面建议加上$符号
    state: {
		socketOpen:false,//socket链接状态
        // 用户信息
        $userInfo: uni.getdata("userInfo")?uni.getdata("userInfo"):false,
		$token:uni.getdata("token")?uni.getdata("token"):"",
		$friend:uni.getdata("friend")?uni.getdata("friend"):[],
		$historylst:uni.getdata("historylst")?uni.getdata("historylst"):{
			//数据格式 Fid+'key':{name:"",Cid:null,length:0,list:[{State":400,"Cid":0,"Fid":0,"Type":"","Topimg":"","Content":"","Time":"","Other":"",Username:"",Phone:null,Name:""}]}
		},
		
		wsurl:'ws://192.168.1.21/ws',
		
    },
	mutations:{
		resetcache(state,arr=[]){
			for(var i in arr){
				let o = arr[i];
				uni.savedata(o.key,o.value,o.time);
			}
		}
	}
})

export default store
